/**
 * @fileoverview   anim/color  Anim 颜色渐变的模块
 * Created by fu.
 * Date: 12-2-15
 * Time: 下午3:42
 */
F.reg('anim/color',function(f,anim){
    anim.color={};

    function hslToRgb(color){
        //#acaacc
        var r,g,b;
        if(color==='transparent'){
            color='#000000';
        }
        r=parseInt(color.slice(1,3),16);
        g=parseInt(color.slice(3,5),16);
        b=parseInt(color.slice(5,7),16);
        //'rgb('+r+','+g+','+b+')';
        return [r,g,b];
    }
    function rgbTOhsl(rgb) {
        if (rgb.indexOf('#') > -1) return rgb;
        var s = '#',colorArr = rgb.match(/\d+/g),
                r = colorArr[0],g = colorArr[1],b = colorArr[2];
        s += parseInt(r, 10) < 16 ? '0' + parseInt(r, 10).toString(16) : parseInt(r, 10).toString(16);
        s += parseInt(g, 10) < 16 ? '0' + parseInt(g, 10).toString(16) : parseInt(g, 10).toString(16);
        s += parseInt(b, 10) < 16 ? '0' + parseInt(b, 10).toString(16) : parseInt(b, 10).toString(16);
        return s;
    }

    anim.color.tween=function(tween,time,basestyle,changestyle,druation){
        var curstyle,r,g,b,basearr,changearr;
            basearr=hslToRgb(basestyle);
            changearr=hslToRgb(changestyle);
        r=tween(time,basearr[0],changearr[0]-basearr[0],druation);
        g=tween(time,basearr[1],changearr[1]-basearr[1],druation);
        b=tween(time,basearr[2],changearr[2]-basearr[2],druation);
        curstyle='rgb('+parseInt(r,10)+','+parseInt(g,10)+','+parseInt(b,10)+')';
     //   console.log( (curstyle))
        return rgbTOhsl(curstyle);
    };
    return anim;
},{
    requires:[

    ]
});